using ERP.Domain.Warehouse.Allocation;
using Repository.communal;

namespace Warehouse.Repository
{
    /// <summary>
    /// 调拨单仓储接口
    /// </summary>
    public interface IAllocationRepository : IBaseRepository<TransferOrder>
    {
        /// <summary>
        /// 获取下一个调拨单号
        /// </summary>
        Task<string> GetNextTransferNoAsync();

        /// <summary>
        /// 根据调拨单号查询调拨单
        /// </summary>
        Task<TransferOrder?> GetByTransferNoAsync(string transferNo);

        /// <summary>
        /// 获取调拨单及其明细
        /// </summary>
        Task<TransferOrder?> GetWithLinesAsync(int transferId);

        /// <summary>
        /// 批量插入调拨单明细
        /// </summary>
        Task InsertLinesAsync(List<TransferOrderLine> lines);

        /// <summary>
        /// 获取调拨单明细
        /// </summary>
        Task<List<TransferOrderLine>> GetLinesAsync(int transferId);

        /// <summary>
        /// 分页查询调拨单列表
        /// </summary>
        Task<(List<TransferOrder> Data, int TotalCount)> GetPagedListAsync(
            int pageIndex, 
            int pageSize, 
            string? transferNo = null,
            int? fromWarehouseId = null,
            int? toWarehouseId = null,
            byte? billStatus = null,
            byte? outStatus = null,
            byte? inStatus = null,
            DateTime? beginDate = null,
            DateTime? endDate = null);

        /// <summary>
        /// 获取调拨单详情（包含明细）
        /// </summary>
        Task<TransferOrder?> GetDetailWithLinesAsync(int transferId);

        /// <summary>
        /// 批量插入调拨出库记录
        /// </summary>
        Task InsertOutRecordsAsync(List<TransferOutRecord> outRecords);

        /// <summary>
        /// 批量插入调拨入库记录
        /// </summary>
        Task InsertInRecordsAsync(List<TransferInRecord> inRecords);

        /// <summary>
        /// 获取调拨出库记录
        /// </summary>
        Task<List<TransferOutRecord>> GetOutRecordsAsync(int transferId);

        /// <summary>
        /// 获取调拨入库记录
        /// </summary>
        Task<List<TransferInRecord>> GetInRecordsAsync(int transferId);

        /// <summary>
        /// 更新调拨单状态
        /// </summary>
        Task UpdateTransferStatusAsync(int transferId, byte? billStatus = null, byte? outStatus = null, byte? inStatus = null);

        /// <summary>
        /// 更新调拨单明细出库数量
        /// </summary>
        Task UpdateLineOutQtyAsync(int lineId, decimal outQty);

        /// <summary>
        /// 更新调拨单明细入库数量
        /// </summary>
        Task UpdateLineInQtyAsync(int lineId, decimal inQty);
    }
}
